package com.house.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.house.common.core.controller.BaseController;
import com.house.common.core.domain.AjaxResult;
import com.house.common.core.domain.entity.DictType;
import com.house.common.core.page.TableDataInfo;
import com.house.system.service.IDictTypeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 字典类型Controller
 * 
 * @author tc
 * @date 2022-02-04
 */
@RestController
@RequestMapping("/entity/dict/type")
public class DictTypeController extends BaseController
{
    @Autowired
    private IDictTypeService dictTypeService;

    /**
     * 查询字典类型列表
     */
    @PreAuthorize("@ss.hasPermi('entity:dict:list')")
    @GetMapping("/list")
    public TableDataInfo list(DictType dictType)
    {
        startPage();
        List<DictType> list = dictTypeService.selectDictTypeList(dictType);
        return getDataTable(list);
    }

    /**
     * 获取字典类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('entity:dict:query')")
    @GetMapping(value = "/{dictId}")
    public AjaxResult getInfo(@PathVariable("dictId") Long dictId)
    {
        return AjaxResult.success(dictTypeService.selectDictTypeByDictId(dictId));
    }

    /**
     * 新增字典类型
     */
    @PreAuthorize("@ss.hasPermi('entity:dict:add')")
    @PostMapping
    public AjaxResult add(@RequestBody DictType dictType)
    {
        return toAjax(dictTypeService.insertDictType(dictType));
    }

    /**
     * 修改字典类型
     */
    @PreAuthorize("@ss.hasPermi('entity:dict:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody DictType dictType)
    {
        return toAjax(dictTypeService.updateDictType(dictType));
    }

    /**
     * 删除字典类型
     */
    @PreAuthorize("@ss.hasPermi('entity:dict:remove')")
	@DeleteMapping("/{dictIds}")
    public AjaxResult remove(@PathVariable Long[] dictIds)
    {
        return toAjax(dictTypeService.deleteDictTypeByDictIds(dictIds));
    }

    /**
     * 刷新字典缓存
     */
    @PreAuthorize("@ss.hasPermi('entity:dict:remove')")
    @DeleteMapping("/refreshCache")
    public AjaxResult refreshCache()
    {
        dictTypeService.resetDictCache();
        return AjaxResult.success();
    }

    /**
     * 获取字典选择框列表
     */
    @GetMapping("/optionselect")
    public AjaxResult optionselect()
    {
        List<DictType> dictTypes = dictTypeService.selectDictTypeAll();
        return AjaxResult.success(dictTypes);
    }
}
